package com.canbot.u05.activity.agenda.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.canbot.u05.R
import com.canbot.u05.activity.agenda.bean.AgendaTypeBean
import com.canbot.u05.activity.agenda.interfaces.IAgendaTypeLisenter

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaTypeAdapter(private val dataList: List<AgendaTypeBean>, private val context: Context, private val iAgendaTypeLisenter: IAgendaTypeLisenter) : RecyclerView.Adapter<AgendaTypeAdapter.AgendaTypeViewHolder>() {
    private val inflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): AgendaTypeViewHolder {
        val inflate = inflater.inflate(R.layout.activity_agenda_create_work_type_item, viewGroup, false)
        return AgendaTypeViewHolder(inflate)
    }

    override fun onBindViewHolder(agendaTypeViewHolder: AgendaTypeViewHolder, i: Int) {
        val agendaTypeBean = dataList[i]
        agendaTypeViewHolder.itemView.setOnClickListener {
            iAgendaTypeLisenter.onSelect(i)
        }
        agendaTypeViewHolder.typeName.text = agendaTypeBean.type
        if (agendaTypeBean.isSelect) {
            agendaTypeViewHolder.btnIsSeletor.visibility = View.VISIBLE
        } else {
            agendaTypeViewHolder.btnIsSeletor.visibility = View.INVISIBLE
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    inner class AgendaTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var typeName: TextView = itemView.findViewById(R.id.type_name)
        var btnIsSeletor: ImageView = itemView.findViewById(R.id.btn_isSeletor)
    }
}
